package work20240729.work1;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Comparator;

public class work1 {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader("src/work20240729/work1/sort.txt"));
        String str = null;
        ArrayList<String> arrList = new ArrayList<>();
        while((str = br.readLine()) != null){
            arrList.add(str);
        }

        sortArr(arrList);
        System.out.println(arrList);
        BufferedWriter bw = new BufferedWriter(new FileWriter("src/work20240729/work1/New_sort.txt"));
        for(String i : arrList){
            bw.write(i);
            bw.newLine();
        }
        bw.close();
        br.close();
    }
    public static void sortArr(ArrayList arr) {
        arr.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                String[] s1 = o1.split("\\.");
                String[] s2 = o2.split("\\.");
                int n1 = s1.length > 0 && !s1[0].isEmpty() ? Integer.parseInt(s1[0]) : Integer.MAX_VALUE;
                int n2 = s2.length > 0 && !s2[0].isEmpty() ? Integer.parseInt(s2[0]) : Integer.MAX_VALUE;
                return n1 - n2;
            }
        });
    }
}
